package cn.itsource.pet.service.impl;

import cn.itsource.pet.domain.Pet;
import cn.itsource.pet.domain.PetDetail;
import cn.itsource.pet.mapper.PetDetailMapper;
import cn.itsource.pet.service.IPetService;
import cn.itsource.basic.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 业务实现类：
 */
@Service
public class PetServiceImpl extends BaseServiceImpl<Pet> implements IPetService {

    @Autowired
    private PetDetailMapper petDetailMapper;

    @Override
    public void add(Pet pet) {
        super.add(pet);//自增id
        if(pet.getPetDetail()!=null){
            PetDetail petDetail = pet.getPetDetail();
            petDetail.setPetId(pet.getId());
            petDetailMapper.save(petDetail);
        }
    }

    @Override
    public void del(Long id) {
        super.del(id);
        //根据宠物的id删除宠物详情
        petDetailMapper.removeByPetId(id);
    }

    @Override
    public void update(Pet pet) {
        super.update(pet);
        if(pet.getPetDetail()!=null){
            PetDetail petDetail = pet.getPetDetail();
            petDetail.setPetId(pet.getId());
            //宠物详情更新：根据宠物详情id去更新
            petDetailMapper.update(petDetail);
        }
    }
}
